package com.gxycoding.websocket.config;

import com.gxycoding.websocket.common.ConstantUtil;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Description(集成clientIp)
 * author: Gao xueyong
 * Create at: 2020/7/15 9:07 下午
 */
@WebListener
public class WebServletRequestListener implements ServletRequestListener {
    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
    }

    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        HttpServletRequest request = (HttpServletRequest) sre.getServletRequest();
        HttpSession session = request.getSession();
        session.setAttribute(ConstantUtil.clinetIp,sre.getServletRequest().getRemoteAddr());
    }
}
